The JSON RPC is included with the Extension Library and provides an entry point for CSJS to interact with the server. Methods inside an RPC are SSJS that can be as simple or as complex as you like. They are an excellent means of kicking off backend Java methods or just doing all the work themselves. Best of all, the JSON RPC is stupid simple to implement and a very powerful feature to enhance and speed up development by cutting down the time and code required to communicate with the server from CSJS.
The JSON RPC shows up in the Component Palette under "" as "Remote Service":
To use it just drag this component onto your xpage and assign the methods/arguments you need for each task that's required to be launched from CSJS. The best placement for the RPC is at the topmost layout level of your application. For example, if you have the layout that wraps the entire application and all the forms, views, pages, etc are within this layout, that's the place to put your RPC. Doing this will make the RPC available everywhere and you only have to define methods once.
Now that you've got the RPC service on your page, define a Service Name for the service. This name is a global CSJS variable and is what will be available for you to use in order to call the methods within the RPC. Once that's done you can add your methods and the required arguments for each method. These methods will be SSJS and have all the functionality of SSJS, which makes it a very useful tool. That's it really for the setup of the RPC. Here's what an RPC's properties look like:
To call the methods you just created within the RPC, assuming you gave it a service name of myRPC with a method of myMethod that has 1 argument which accepts a string, you can just issue the following CSJS:
You can also include a callback that runs once the RPC has completed running it's method code by using the following CSJS pattern:
console.log("the response is " + response);
So as you can see, the JSON RPC is a great addition to the Extension Library that makes it very easy to communicate with the server from CSJS.